﻿using Microsoft.VisualStudio.Editor;
using Microsoft.VisualStudio.Language.Intellisense;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.TextManager.Interop;
using Microsoft.VisualStudio.Utilities;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PC.PickleJar.VisualStudioIntegration.AutoCompletion
{
	[Export(typeof(IVsTextViewCreationListener))]
	[Name("token completion handler")]
	[ContentType("Code")]
	[TextViewRole(PredefinedTextViewRoles.Editable)]
	internal class SourceItemCompletionHandlerProvider : IVsTextViewCreationListener
	{
		public void VsTextViewCreated(IVsTextView textViewAdapter)
		{
			ITextView textView = this.AdapterService.GetWpfTextView(textViewAdapter);
			if (textView == null)
				return;

			Func<SourceItemCompletionCommandHandler> createCommandHandler = delegate()
			{
				return new SourceItemCompletionCommandHandler(textViewAdapter, textView, this);
			};

			textView.Properties.GetOrCreateSingletonProperty(createCommandHandler);
		}

		[Import]
		internal IVsEditorAdaptersFactoryService AdapterService
		{
			get;
			set;
		}

		[Import]
		internal ICompletionBroker CompletionBroker
		{
			get;
			set;
		}

		[Import]
		internal SVsServiceProvider ServiceProvider
		{
			get;
			set;
		}
	}
}
